package com.jastar.android.game.richman.logic.handler;

import com.jastar.android.game.richman.GameActivity;
import com.jastar.android.game.richman.logic.Event.Event;
import com.jastar.android.game.richman.logic.bean.Cell;
import com.jastar.android.game.richman.logic.bean.Player;
import com.jastar.android.game.richman.logic.enums.CellType;
import com.jastar.android.game.richman.logic.weight.WeightSet;

import java.util.ArrayList;
import java.util.List;

/** 随机事件的公共类 */
public abstract class CellEventHandler extends CellDefaultHandler {

    private final WeightSet<Event> weightSet;

    public CellEventHandler() {
        List<Event> events = new ArrayList<>();
        initEvents(events);
        weightSet = new WeightSet<>(events);
    }

    @Override
    public void hand(GameActivity activity, Cell cell, Player p, CellType.Callback callback) {
        Event item = weightSet.random();
        item.hand(activity, cell, p, callback);
    }

    protected abstract void initEvents(List<Event> events);

}
